package com.ruoyi.web.controller.mes;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.web.domain.mes.MesPrintTechnology;
import com.ruoyi.web.domain.mes.MesPrintTechnologyDetail;
import com.ruoyi.web.domain.mes.MesTechnologyStandard;
import com.ruoyi.web.service.MesPrintTechnologyService;
import com.ruoyi.web.service.MesTechnologyStandardService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/mesTechnologyStandard")
public class MesTechnologyStandardController extends BaseController {

    @Resource
    private MesTechnologyStandardService mesTechnologyStandardService;
    @PostMapping(value = "/list")
    public TableDataInfo list(@RequestBody Map<String, String> params) {
        startPage(params);
        String technologyType = params.get("technologyType");//工艺类型
        List<MesTechnologyStandard> data = mesTechnologyStandardService
                .list(new QueryWrapper<MesTechnologyStandard>().lambda()
                        .eq(StringUtils.isNotEmpty(technologyType),MesTechnologyStandard::getTechnologyType,technologyType)
                        .eq(StringUtils.isNotEmpty(params.get("bookType")),MesTechnologyStandard::getBookType,params.get("bookType"))
                );
        TableDataInfo list = getDataTable(data);
        return list;
    }
    @PostMapping(value = "/getById")
    public AjaxResult getById(@RequestBody Map<String, String> params) {
        String id = params.get("id");
        MesTechnologyStandard mesTechnologyStandard = mesTechnologyStandardService.getById(id);
        return AjaxResult.success("查询成功", mesTechnologyStandard);
    }
    @PostMapping(value = "/addOrupdate")
    @Transactional
    public AjaxResult add(@RequestBody MesTechnologyStandard mesTechnologyStandard) {
        mesTechnologyStandardService.saveOrUpdate(mesTechnologyStandard);
        return AjaxResult.success("操作成功", mesTechnologyStandard.getId());
    }
    @PostMapping(value = "/deleteById")
    public AjaxResult deleteById(@RequestBody Map<String, String> params) {
        String id = params.get("id");
        mesTechnologyStandardService.removeById(id);
        return AjaxResult.success("删除成功");
    }
}
